package ro.gateway.aida.usr;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;



/**
 * Created by IntelliJ IDEA.
 * User: xblue
 * Date: Jun 3, 2003
 * Time: 6:28:46 PM
 * To change this template use Options | File Templates.
 */
public class UserUtils
{

      public static User getLogged( HttpServletRequest request )
      {
            User user = ( User ) request.getSession().getAttribute( UserConstants.
                  LOGGED_USER );
            HttpSession session = request.getSession();
            if ( user == null )
            {
                  //TE OMOR!! ti-am zis ca imi invalidai sesiunea undeva :))
                  //session.invalidate();
                  /*
                  try {
                    response.sendRedirect(request.getContextPath() + "/login.jsp");

                  }
                  catch (IOException ex) {
                    ex.printStackTrace();
                  }*/
            }
            return user;
      }

      /**
       * Verifies if user is logged in. Redirects unlogged user to login.jsp
       * @param request
       * @param response
       * @return the logged user bean
       */
      public static User getLogged( HttpServletRequest request,
                                    HttpServletResponse response )
      {
            User user = ( User ) request.getSession().getAttribute( UserConstants.
                  LOGGED_USER );
            HttpSession session = request.getSession();
            if ( user == null )
            {
                  //   session.invalidate();
                  /*
                  try {
                    response.sendRedirect(request.getContextPath() + "/login.jsp");

                  }
                  catch (IOException ex) {
                    ex.printStackTrace();
                  }*/
            }
            return user;
      }


}
